const fs = require('fs')
// https://at.alicdn.com/t/c/font_3500651_l9b2nwed3zn.js
const base = 'https://at.alicdn.com/t/c'
const download = require('download')
const inquirer = require('inquirer')
// 请输入icon地址
async function inputIconAddress(message = '请输入iconfont地址:') {
  const answer = await inquirer.prompt({
    type: 'input',
    name: 'url',
    message
  })
  if (!answer.url) {
    inputIconAddress('请输入iconfont地址:')
  } else {
    saveFile(answer.url)
  }
}
const saveFile = async(url) => {
  const cssUrl = `${base}/${url}.css`
  const jsUrl = `${base}/${url}.js`
  // 确保文件夹存在
  if (!fs.existsSync('./automation/static')) {
    fs.mkdirSync('./automation/static')
  }
  await download(cssUrl, './automation/static', {
    filename: 'iconfont.css'
  })
  console.log('iconfont.css 已完成下载')

  await download(jsUrl, './automation/static', {
    filename: 'iconfont.js'
  })
  console.log('iconfont.js 已完成下载')
}
inputIconAddress()
